//
//  BlindFailView.m
//  iiecg
//
//  Created by 123456 on 2017/11/21.
//  Copyright © 2017年 Boundary Technology. All rights reserved.
//

#import "BlindFailView.h"
#import "Masonry.h"
#import "UIView+Corner.h"

@interface BlindFailView ()

@property (nonatomic,strong)UILabel *labOne;

@property (nonatomic,strong)UILabel *labTwo;

@property (nonatomic,strong)UILabel *titleLabel;

@property (nonatomic,strong)MASConstraint *greenViewLeft;

@property (nonatomic,strong)MASConstraint *greenViewright;

@end

@implementation BlindFailView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setUpUI];
    }
    return self;
}

-(void)setOneTitle:(NSString *)titleone andTitleTwo:(NSString *)titleTwo andTitle:(NSString *)title
{
    [self.greenViewLeft uninstall];
    [self.greenViewright uninstall];
    __block CGFloat lab1W = [IKPublicUtil widthForString:titleone fontSize:14];
    __block CGFloat lab2W = [IKPublicUtil widthForString:titleTwo fontSize:14];
    [self.labOne mas_updateConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        self.greenViewLeft = make.left.mas_equalTo((KScreenW - lab1W)/2.0);
        make.height.mas_equalTo(60);
        make.top.equalTo(self.titleLabel.mas_bottom);
    }];
    
    [self.labTwo mas_updateConstraints:^(MASConstraintMaker *make) {
        self.greenViewright = make.left.equalTo(self.labOne.mas_left);
        make.width.mas_equalTo(lab2W);
        make.height.mas_equalTo(30);
        make.top.equalTo(self.labOne.mas_bottom).with.offset(10);
    }];
    
    [IKPublicUtil runOnMainThread:^{
        
        [self layoutIfNeeded];
        self.labOne.text = titleone;
        self.labTwo.text = titleTwo;
        self.titleLabel.text = title;
    }];
}

-(void)setUpUI
{
    self.backgroundColor = ECG_COLOR_WHITE;
    
    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ecg_blind_fail"]];
    [self addSubview:imageView];
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.top.equalTo(self.mas_top).with.offset(60);
        make.width.and.height.mas_offset(120);
    }];
    
    UILabel *label0 = [[UILabel alloc] init];
    self.titleLabel = label0;
//    label0.text = @"添加失败";
    label0.font = FONT_BASIC;
    label0.textColor = COLOR_BLACK_6F6F6F;
    label0.textAlignment = NSTextAlignmentCenter;
    [self addSubview:label0];
    [label0 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.centerX.equalTo(self);
        make.top.equalTo(imageView.mas_bottom).with.offset(20);
        make.height.mas_equalTo(35);
    }];
    
    UILabel *lab1 = [[UILabel alloc] init];
    self.labOne = lab1;
    lab1.numberOfLines = 0;
    lab1.textAlignment = NSTextAlignmentCenter;
//    lab1.text = @"1,请检查设备开关是否打开";
    lab1.font = FONT_LABEL;
    lab1.textColor = [UIColor grayColor];
    [self addSubview:lab1];
    [lab1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(label0.mas_bottom).with.offset(10);
        self.greenViewLeft = make.left.mas_equalTo(30);
        make.centerX.equalTo(self);
        make.height.mas_equalTo(60);
    }];
    
    UILabel *lab2 = [[UILabel alloc] init];
    self.labTwo = lab2;
//    lab2.text = @"2,请尝试更换电池";
    lab2.font = FONT_LABEL;
    lab2.textAlignment = NSTextAlignmentLeft;
    lab2.textColor = [UIColor grayColor];
    [self addSubview:lab2];
    [lab2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lab1.mas_bottom).with.offset(8);
        self.greenViewright = make.left.mas_equalTo(30);
        make.centerX.equalTo(self);
        make.height.mas_equalTo(30);
    }];
    
    UIButton *blindingButton = [[UIButton alloc] init];
    [blindingButton setTitle:INTERNATIONAL(@"string_rebond") forState:UIControlStateNormal];
    [blindingButton setTitleColor:ECG_COLOR_WHITE forState:UIControlStateNormal];
    [blindingButton addTarget:self action:@selector(reBlind) forControlEvents:UIControlEventTouchUpInside];
    blindingButton.titleLabel.font = FONT_BUTTON;
    blindingButton.backgroundColor = COLOR_PALETTE_LIGHT_GREEN;
    blindingButton.cornerRadius = 25;
    [self addSubview:blindingButton];
    [blindingButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(30);
        make.right.mas_equalTo(-30);
        make.top.equalTo(lab2.mas_bottom).with.offset(10);
        make.height.mas_equalTo(50);
    }];
    
    UILabel *lab3 = [[UILabel alloc] init];
    lab3.text = INTERNATIONAL(@"string_final_plan");
    lab3.textColor = [UIColor grayColor];
    lab3.textAlignment = NSTextAlignmentCenter;
    lab3.font = FONT_LABEL;
    [self addSubview:lab3];
    [lab3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.centerX.equalTo(self);
        make.height.mas_equalTo(30);
        make.bottom.equalTo(self.mas_bottom).with.offset(-49-30);
    }];
}

-(void)reBlind
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(callbackreblindDevice)])
    {
        [self.delegate callbackreblindDevice];
    }
}

@end

